export const getRowAndCol = () => {
  const data = window.luckysheet.getSheetData();
  let maxRow = 0;
  let maxCol = 0;
  data.forEach((row: any, rowIndex: number) => {
    row.forEach((cell: any, colIndex: number) => {
      if (cell != null && cell.v != null) {
        // 检查单元格和它的值是否不为null
        maxRow = Math.max(maxRow, rowIndex + 1); // 更新最大行
        maxCol = Math.max(maxCol, colIndex + 1); // 更新最大列
      }
    });
  });
  return {
    row: maxRow,
    col: maxCol,
  };
};

export const getRowColumn = () => {
  const data = window.luckysheet.getSheetData();
  let objRowColumn: any = {
    row: [null, null],
    column: [null, null],
  };
  data.forEach((row: any, rowIndex: number) => {
    row.forEach((cell: any, colIndex: number) => {
      if (cell != null && cell.v != null) {
        if (objRowColumn.row[0] === null) {
          objRowColumn.row[0] = rowIndex;
        }
        objRowColumn.row[1] = rowIndex;
        if (objRowColumn.column[0] === null) {
          objRowColumn.column[0] = colIndex;
        }
        objRowColumn.column[1] = colIndex;
      }
    });
  });
  return objRowColumn;
};

export function isValidDate(dateString: string) {
  const timestamp = Date.parse(dateString);
  return !isNaN(timestamp);
}
